<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录验证</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
    }

    form {
      background-color: white;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
      width: 300px;
      margin: 50px auto;
    }

    label {
      display: block;
      margin-bottom: 5px;
    }

    input {
      width: 100%;
      padding: 8px;
      margin-bottom: 15px;
      border: 1px solid #ccc;
      border-radius: 3px;
    }

    button {
      background-color: #007BFF;
      color: white;
      padding: 10px 15px;
      border: none;
      border-radius: 3px;
      cursor: pointer;
    }

    button:hover {
      background-color: #0056b3;
    }
  </style>
</head>

<body>
  <form id="loginForm">
    <label for="username">用户名:</label>
    <input type="text" id="username" placeholder="请输入用户名">
    <label for="email">邮箱:</label>
    <input type="email" id="email" placeholder="请输入邮箱">
    <label for="password">密码:</label>
    <input type="password" id="password" placeholder="请输入密码">
    <button type="button" onclick="validateForm()">登录</button>
  </form>

  <script>
    function validateForm() {
      const username = document.getElementById('username').value;
      const email = document.getElementById('email').value;
      const password = document.getElementById('password').value;

      const usernameError = document.createElement('span');
      const emailError = document.createElement('span');
      const passwordError = document.createElement('span');

      let isValid = true;

      // 验证用户名
      if (username.length < 3) {
        usernameError.textContent = '用户名必须至少3个字符！';
        usernameError.style.color ='red';
        document.getElementById('username').parentNode.appendChild(usernameError);
        isValid = false;
      }

      // 验证邮箱
      const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
      if (!emailRegex.test(email)) {
        emailError.textContent = '请输入有效的邮箱！';
        emailError.style.color ='red';
        document.getElementById('email').parentNode.appendChild(emailError);
        isValid = false;
      }

      // 验证密码
      if (password.length < 6) {
        passwordError.textContent = '密码必须至少6个字符！';
        passwordError.style.color ='red';
        document.getElementById('password').parentNode.appendChild(passwordError);
        isValid = false;
      }

      if (isValid) {
        alert('验证成功，可以进行下一步操作！');
      }
    }
  </script>
</body>

</html>